import Vue from 'vue'
import Vuex from 'vuex'
//驼峰命名
import camelCase from 'lodash/camelCase'

Vue.use(Vuex)

const requireModule = require.context('./modules', false, /\.js$/)
const modules = {}

requireModule.keys().forEach(fileName => {
  if (fileName === './index.js') return
  const moduleName = camelCase(fileName.replace(/(\.\/|\.js)/g, ''))
  modules[moduleName] = {
    namespaced: true,
    ...requireModule(fileName),
  }
})

export default new Vuex.Store({
  state: {},
  //同步变更
  mutations: {},
  //异步变更，提交的是 mutation
  actions: {},
  getters: {},
  modules: modules
})
